import pymysql

conn = pymysql.connect(
    host = 'localhost',
    port = 3306,
    user = 'root',
    passwd = '123456',
    db = 'gamedb',
    charset = 'utf8'
)
cursor = conn.cursor()

#增
insert_sql = 'insert into user values (%s,%s)'

#cursor.execute(insert_sql,('yaya',18))
#conn.commit()

#cursor.executemany(insert_sql,[('jingjing',21),('yaya',17),('jingya',23),('jie',99)])
#conn.commit()

##查
#select_sql = 'select * from user'
#
#cursor.execute(select_sql)
#
#result1 = cursor.fetchone()
#print(result1)
#print('*' * 20)
#result2 = cursor.fetchmany(2)
#print(result2)
#print('*' * 20)
#result3 = cursor.fetchall()
#print(result3)
#print('*' * 20)
#
##改
#update_sql = 'update user set name = %s where age = %s'
#
#cursor.execute(update_sql,('dabaoben',21))
#conn.commit()

#删
delete_sql = 'delete from user where age = %s'
r = cursor.execute(delete_sql,21)
conn.commit()

cursor.close()
conn.close()
print('data save select update ok')

